#ifndef XGE_XFONT_H_
#define XGE_XFONT_H_
#include "xge_common_config.h"
#include "xstring.h"
#include "xtype.h"
#include "xsmart_ptr.h"
#include "g_colors.h"
#include "xtimer.h"

namespace xge{

  using graphics::Color;
  using xge_internal::Timer;

  // A font just represents a font service provided by the sub-system 
  // It will not be fixed to a certain type of font service , such as
  // BitMapFont( typically very usual style font ) or Vector Font ( using
  // FreeType as well ).

  class Font {
  public:
    enum {
      TRUE_TYPE_FONT , 
      BITMAP_FONT 
    };
    // Write a string using this font to the rendering target 
    virtual void WriteString( const Rect& string_rect , const String& string_message ) = 0;
    void WriteString( const Rect& string_rect, const char_t* format , ... );
  public:
    // Setting the font style here 
    void set_hscale( float hscale ) {
      hscale_ = hscale;
    }
    void set_vscale( float vscale ) {
      vscale_ = vscale;
    }
    void set_rotation( float rotation ) {
      rotation_ = rotation;
    }
    void set_color( const Color& color ) {
      color_ = color;
    }
    float hscale () const {
      return hscale_;
    }
    float vscale () const {
      return vscale_;
    }
    float rotation() const {
      return rotation_;
    }
    const Color& color() const {
      return color_;
    }

  public: 
    // font style rendering stuff 
    enum {
      FONT_STYLE_NORMAL , // this is the normal way for rendering the font 
      FONT_STYLE_VCENTER, // this is another way for rendering the font , it will make the font in the center in vertical direction 
      FONT_STYLE_HCENTER, // this will make the font horizontal direction center 
      FONT_STYLE_ONCE   , // this will make the font write the whole string in one call .
      FONT_STYLE_TYPE_STYLE, // this will make the font write the whole string like type in , 
      // and the diff_time parameter can be setted , which means how many time tick( mili-second ) when
      // char_number output to the screen .
    };
    // set the font style
    virtual void set_font_style( int style , const Timer::tick_t& time_diff , int char_number = 1 ) {
      time_diff_ = time_diff;
      char_number_ = char_number;
      style_ = style;
    }
    int style() const {
      return style_;
    }
    const Timer::tick_t& time_diff() const {
      return time_diff_;
    }
    int char_number() const {
      return char_number_;
    }

    int type() const {
      return type_;
    }


    Font( int type ) : type_(type){}


    virtual ~Font(){}
  public:
    // Ansychronization stuff 
    // The font (in default) will using ansychronization way to
    // output to the target .In fact , if you choose to use the
    // TrueType , the font will using the back thread to do the 
    // rasterization and than doing the rendering stuff ,in addition 
    // the font will also make use of the local cache to reduce the
    // rasterization calling , so the font will finally be stable
    // on the rendering way .

    virtual void set_synchronization( bool sync ) {
      sync_ = sync;
    }

    bool synchronization() const {
      return sync_;
    }


  private:
    Color color_;
    float hscale_,vscale_,rotation_;
    bool sync_;
    bool linerable_rendering_;
    int style_;
    Timer::tick_t time_diff_;
    int char_number_;
    int type_;
  };

  // The font will only be used in the rendering thread ( Main Thread )
  // so it does not need thread safe .

  typedef xge::xge_internal
    ::SharedPtr< Font , xge::xge_internal::DefaultDestructor<Font> , xge::xge_internal::CommonOperationPolicy > FontPtr;



}// namespace xge

#endif// XGE_XFONT_H_